<template>
	<view class="vipserver">
		<navbar left-text="退后" right-text="分享" @clickLeft="gobackfunction"></navbar>
		<view class="">
			<view class="class">
				<view class="c-name">
					年级:
				</view>
				<picker class="c-con" :range="val_class" @change="changcut_class">
					<view>{{val_class[cut_class]}}</view>
				</picker>
			</view>
		</view>
		<view class="science">
			<view class="c-name">
				选择科目:
			</view>
			<picker class="c-con" :range="val_science" @change="changcut_science">
				<view>{{val_science[cut_science]}}</view>
			</picker>
		</view>
		<view class="situation">
			<view class="">
				学习情况:
			</view>
			<textarea v-model="situation" class="sit-text" name="" id="" cols="30" rows="10"
				placeholder="详细描述孩子的情况"></textarea>
		</view>
		<view class="power">
			<label class="radio" @click="powerstate = !powerstate">
				<radio :checked="powerstate"  /><text></text>
				<view class="">
					因虚假信息而引发的任何后果，一概由填表人负责，与本站无关。
				</view>
			</label>

		</view>
		<!-- 立即预约 -->
		<view class="butt">
			<button class="but" @tap="online">立即预约</button>
		</view>
		<view v-if="isShow" class="reserva-detal" @touchmove.stop.prevent="">
			<!-- 阴影框 -->
			<view class="pop-mask" @tap="hidePop">

			</view>
			<view class="pop-box" :animation="animationData">
				<view class="pop-btitle">
					预约需求:
				</view>
				<mline></mline>
				<view class="pop-line">
					<view class="line-top">
						学生详细情况:
					</view>
					<mline></mline>
					<view class="line-moy">
						授课年级:{{val_class[cut_class]}}-{{val_science[cut_science]}}
					</view>
					<mline></mline>
					<view class="">
						学生情况:{{situation}}
					</view>
				</view>

				<view class="pop-sub" @tap="gopay">
					预约
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import navbar from "@/components/uni/uni-nav-bar/uni-nav-bar.vue"
	import mline from '@/components/common/Lines.vue'
	import $http from '@/common/api/request.js'
	export default {
		data() {
			return {
				submitform:{
					situation:"",
					val_class:[],
					val_science: [],
					cut_class: 0, // 学员科目索引
					cut_science: 0, // 学员年级索引
				},
				situation: "",
				val_class: [],
				cut_class: 0, // 学员科目索引
				val_science: [],
				cut_science: 0, // 学员年级索引
				isShow: false,
				powerstate: false,
				animationData: {}, //动画过渡
				content:[
					"您的孩子处于小学阶段,孩子教育应该以互动式教学，快速提升对学习兴趣，培养学习习惯，塑造逻辑思维能力.","您的孩子处于初一,二阶段,孩子教育应该以带动学习积极性,提高学习效率,培养综合能力.","您的孩子处于初三阶段,孩子教育应该以结合学生情况制定有效教学思路,重在提升应试能力.","您的孩子处于高一,二阶段,孩子教育应该以针对性拓展拔高,打牢基础的同时提升综合应用能力.","您的孩子处于高三阶段,孩子教育应该以高考直通车,有效提升学生应试能力."
				],
				rules:{
					cut_science:{
						rule: /^(?!0$)\d+$/,
						msg: "辅导科目不可以不填写"
					},
					cut_class:{
						rule: /^(?!0$)\d+$/,
						msg: "辅导年级不可以不填写"
					},
					situation:{
						rule:/.{2,200}$/,
						msg: "学员情况尚未填写,智能推荐需要更多的信息哦"
					}
				}
			};
		},
		components: {
			navbar,mline
		},
		onLoad() {
			this.getbaselist()
		},
		methods: {
			changcut_class(e) {
				this.cut_class = e.target.value;
			},
			changcut_science(e) {
				this.cut_science = e.target.value;
			},
			//正则校验
			validate(key){
				let bool = true;
				if(!this.rules[key].rule.test(this[key])){
					uni.showToast({
						title:this.rules[key].msg,
						icon:"none"
					})
					bool = false;
					return bool;
				}
				return bool;
			},
			//获取基本表结构数据:
			getbaselist(){
				$http.request({
					url: "/reservation_s",
					method: "POST",
					header: {
						token: true
					},
				}).then((res) => {
					uni.showToast({
						title: "获取数据中...",
						icon: "none",
						mask: true,
						duration: 200,
						success: () => {
							this.val_science = res.val_science;
							this.val_class = res.val_class;
						}
					})
				}).catch(() => {
					uni.showToast({
						title: "请登录后操作..",
						icon: "error",
						mask: true,
						duration: 2000,
					})
				})
			},
			//白框下 立即预约 的回调
			online() {
					
				if( ! this.powerstate){
					uni.showToast({
						title:"协议未勾选",
						icon:"none"
					})
					return 
				}
				if(this.validate('cut_science') && this.validate('cut_class') && this.validate('situation') ){
					this.isShow = true;
				}
				
				
			},
			//弹阴影框的预约回调:
			gopay() {
				if(this.cut_class=== 1){
					this.showtheModal(0);
				}else if(this.cut_class === 2 || this.cut_class === 3){
					this.showtheModal(1);
				}else if(this.cut_class === 4){
					this.showtheModal(2);
				}else if(this.cut_class === 5|| this.cut_class === 6){
					this.showtheModal(3);
				}else{
					this.showtheModal(4);
				}
				},
			//弹框提示:
			showtheModal(num){
				
					uni.showModal({
						title:"推算分析..",
						content:this.content[num],
						success: (res)=> {
						   			 if (res.confirm) {
						   			      // 在这里可以执行确认操作
										  this.getdatalist();
						   			    } else{
											
										}
						   		}
					})
				},
			//获取VIP教师的接口函数
			//跳转到vipteacherlist页面
			getdatalist(){
				this.submitform.situation = this.situation;
				this.submitform.val_class = this.val_class
				this.submitform.cut_class = this.cut_class
				this.submitform.val_science = this.val_science
				this.submitform.cut_science = this.cut_science
					uni.navigateTo({
						url:`/pages/vipteacherlist/vipteacherlist?submitform=${JSON.stringify(this.submitform)}`
					})
					
				},
			//隐藏蒙层
			hidePop() {
					var animation = uni.createAnimation({
						duration: 200,
					})
					animation.translateY(0).step()
					this.animationData = animation.export()
					setTimeout(() => {
						animation.translateY(600).step()
						this.isShow = false;
					}, 200)
				
				},
				//关闭按钮的回调函数:
			gobackfunction(){
					uni.navigateBack({
					delta: 1
				})
			}
			},
			
		}

</script>

<style lang="scss">
	.class,
	.science,
	.situation,
	{
	display: flex;
	border-bottom: 1rpx solid #15aeff;
	justify-content: space-between;
	flex-wrap: wrap;
	font-size: 30rpx;
	padding: 20rpx;

	.c-name {}

	.c-con {}
	}

	.power {
		.radio {
			display: flex;
		}
	}

	.butt {
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100%;

		.but {
			background-color: #1a9c34;
			color: #FFF;
		}

	}

	.reserva-detal {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 999;

		.pop-mask {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0, 0, 0, .6);
		}

		.pop-box {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			background-color: #ffffff;
			border-radius: 30rpx;

			.pop-btitle {
				text-align: center;
			}

			.pop-top {
				display: flex;
				padding: 20rpx 20rpx;

				.pop-img {
					width: 40%;
					height: 360rpx;
				}

				.pop-img-right {
					width: 50%;
					flex-wrap: wrap;
					align-items: flex-end;
					padding: 5rpx 20rpx;
					margin-top: 175rpx;
				}
			}

			.pop-line {
				font-size: 28rpx;

				.line-top {}

				.line-moy {
					padding: 10rpx;
				}

			}

			.pop-sub {
				z-index: 9999;
				line-height: 80rpx;
				background-color: #498DFB;
				color: #FFFFFF;
				text-align: center;
			}
		}
	}
</style>